package com.lxyk.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/Resful")
public class ControllerTest02 {
    @RequestMapping("/test01")
    public String test( int a,int b,Model model)
    {
        int sum = a+b;
        model.addAttribute("msg",sum);
        return "test02";
    }

    @RequestMapping(value = "/test02/{a}/{b}",method = {RequestMethod.GET})
    public String test02(@PathVariable int a, @PathVariable int b, Model model)
    {
        int sum = a+b;
        model.addAttribute("msg",sum);
        return "test02";
    }


    @GetMapping("/test03")
    public String test03(Model model)
    {

        model.addAttribute("msg","哈哈哈");
        //默认情况下是转发
        return "test01";
    }

    @RequestMapping("/test04")
    public String test04(Model model)
    {
        model.addAttribute("msg","123456");
        return "forward:/WEB-INF/jsp/test01.jsp";
    }

    /*@RequestMapping("/test05")
    public String test05(Model model)
    {
        model.addAttribute("msg","123456789");
        *//*重定向*//*
        return "redirect:/WEB-INF/jsp/test01.jsp";
    }*/

    @RequestMapping("/test06")
    public String test06(Model model)
    {
        model.addAttribute("msg","123456789");
        /*重定向*/
        return "redirect:/Resful/test04";
    }

    @RequestMapping("/test07")
    public String test07(String name, Model model)
    {
        System.out.println(name);
        model.addAttribute("msg",name);
        return "hello";
    }
}
